<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;

$this->title = '订单详细';
$this->params['breadcrumbs'][] = $this->title;

$is_merge = false;
$models = $model->room; 

foreach($models as $v){
    if($model->product->stock == 1) {

        $name = $v->productRoom->room->name;
        $v->productRoom->room->code;

    }elseif($model->product->stock == 2){ // 海外航线
        $t = json_decode($model->product->rooms, true);
        $name = isset($t[$v->room_id]['name']) ? $t[$v->room_id]['name'] : '异常';
    }
    $arr[$name][] = $v->id;
    
    //  是否有选择拼房
    if($model->is_merge == 2){
        if($v->merge_id){
            $is_merge = 1;
        }
    }
}

?>

<style type="text/css">
	.title{padding: 15px;background-color: #FFFFFF;text-align: center;font-size:16px;}
	.title-1{padding: 10px;background-color: #FFFFFF;font-size: 16px;border-top:1px solid #ddd;color: #a664a6;}
	.room-title{padding: 10px;background-color: #FFFFFF;font-size: 14px;border-top:1px solid #ddd;color: #FDAD38;}
	.room-detail .customer{padding: 20px;background-color: #FFFFFF;border-top:1px solid #ddd;font-size: 13px;}
	
    .mui-card{margin: 0px;margin-bottom: 10px;border-radius: 0;}
    .line-btn{border: 1px solid #a664a6;color: #FFFFFF;background-color: #a664a6;}
    .list{margin: 15px;line-height: 30px;}
    .jine{float: right;margin-right:15px;}
    .sp1{color: #333;border-bottom: 1px solid #000000}
    .sp2{color: #333;margin-left: 20px;}

    .layer-row{margin-top: 10px;}
    .layer-row label{width: 30%;float: left;line-height: 34px;}
    .layer-row input{width: 60%;height: 16px;float: left;}
    .layer-row .box{width: 65%}
    h3{margin: 0}
</style>

	
<div class="mui-content">

	<div class="mui-card">
    	<div class="mui-card-header">创建时间：<?=$model->created_at?></div>
        <div class="mui-card-content">
            <div class="mui-row list">
                <div class="mui-col-xs-8">
                    <span style="color: #333;">
                    <?=sprintf("来源：%s",yii::$app->params['order_source'][$model->source])?>
                    </span>
                </div>
                <div class="mui-col-xs-4">
                    <span class="jine" style="color: #333;"><?=yii::$app->params['order_status'][$model->status]?></span>
                </div>
            </div>
            <div class="mui-row list">
                <div class="mui-col-xs-8">
                    <span style="color: #333;">
                    <?php if(!empty($model->username) && !empty($model->phone)){
                                             $str = '/';
                                        }else{
                                             $str = ''; 
                                        };
                                    ?>
                    <?=sprintf("联系人:%s%s%s",$model->username,$str,$model->phone)?>
                    </span>
                </div>
                <!-- <div class="mui-col-xs-4">
                    <span class="jine" style="color: #333;">
                        </?php if($model->status < 3){ ?>
                        <a href="/member/member/check-status?id=</?=$model->id?>" data-link="as" class="mui-btn mui-pull-right line-btn" style="padding:4px 10px">已付款</a>
                        </?php }?>
                    </span>
                </div> -->
            </div>
            <div class="mui-row list">
                <div class="mui-col-xs-8">
                    <span style="color: #333;">
                    <?=sprintf("公司:%s",$model->company)?>
                    </span>
                </div>
                <div class="mui-col-xs-4">
                    <span class="jine" style="color: #333;">
                        <?= ($model->status < 10)? Html::a('取消', ['/member/member/unrecovery', 'id' => $model->id], [
                                'class' => 'mui-btn mui-pull-right line-btn',
                                'style' => 'padding:4px 10px',
                                'data' => [
                                    'confirm' => '确定取消该订单吗?',
                                    'method' => 'post',
                                ],
                            ]) : '已取消' 
                      ?>  
                    </span>
                </div>
            </div>
            <div class="box" style="background-color: #666666;color: #FFFFFF;padding-top: 10px;padding-bottom: 10px;">
                <div class="mui-row list">
                    <div class="mui-col-xs-4">
                        <span><?=sprintf("总价:￥%s",floor($model->total_sale))?></span>
                    </div>
                    <div class="mui-col-xs-4">
                        <span><?=sprintf("优惠金额:￥%s",floor($model->sale_price))?></span>
                    </div>
                    <div class="mui-col-xs-4">
                        <span><?=sprintf("实际金额:￥%s",floor($model->price))?></span>
                    </div>
                </div>
            </div>

            <div class="mui-row list">
                <div class="mui-col-xs-12">
                     <a class="mui-btn mui-btn-danger" data-link="as" href="/member/member/order-room?id=<?=$model->id?>"><i class="iconfont" style="font-size: 16px;">&#xe625;</i>添加舱房</a>
                </div>
            </div>

            <div class="mui-row list">
                <?php foreach($model->room as $r){?>    
                    <div class="mui-col-xs-12"> 
                    <?php if($model->product->stock == 1){ //标准格式?> 
                        <p class="sp1">
                            <span>
                            <?php if($model->is_merge == 2){ ?>
                            <?php if($is_merge){ ?>
                                <?php if($r->merge_id){ ?> 
                                    <a class="mui-btn mui-btn-danger" data-link="as" href="/member/member/merge-list?id=<?= $model->id?>&room_id=<?= $r->id ?>" style="height: 25px;line-height: 15px;" ><i class="iconfont" style="font-size: 16px;">&#xe6c2;</i></a>
                                <?php } ?>
                                <?php }else{  ?>
                                    <a class="mui-btn mui-btn-primary"  data-link="as" href="/member/member/merge-list?id=<?= $model->id?>&room_id=<?= $r->id ?>" style="height: 25px;line-height: 15px;"><i class="iconfont" style="font-size: 16px;">&#xe6c2;</i></a>
                                <?php } } ?>
                            <?=sprintf("%s%s %s人房",$r->productRoom->room->name,$r->productRoom->room->code,$r->productRoom->people)?>
                            </span>
                            <span class="mui-pull-right">
                                 <a class="mui-btn mui-btn-danger refund" style="height: 25px;line-height: 15px;" data-id="<?=$r->id?>" data-name='<?=sprintf("%s%s %s人房",$r->productRoom->room->name,$r->productRoom->room->code,$r->productRoom->people)?>'><i class="iconfont" style="font-size: 16px;">&#xe6bf;</i></a>
                            </span>
                        </p>
                    <?php }else if($model->product->stock == 2){//自定义格式?>

                        <?php $rooms = json_decode($model->product->rooms,true);?>
                        <p class="sp1">
                            <span>
                            <?php if($model->is_merge == 2){ ?>
                            <?php if($is_merge){ ?>
                                <?php if($r->merge_id){ ?> 
                                    <a class="mui-btn mui-btn-danger" data-link="as" href="/member/member/merge-list?id=<?= $model->id?>&room_id=<?= $r->id ?>" style="height: 25px;line-height: 15px;" ><i class="iconfont" style="font-size: 16px;">&#xe6c2;</i></a>
                                <?php } ?>
                                <?php }else{  ?>
                                    <a class="mui-btn mui-btn-primary"  data-link="as" href="/member/member/merge-list?id=<?= $model->id?>&room_id=<?= $r->id ?>" style="height: 25px;line-height: 15px;"><i class="iconfont" style="font-size: 16px;">&#xe6c2;</i></a>
                            <?php } } ?>
                            <?=$rooms[$r->room_id]['name']?></span>
                            <span class="mui-pull-right">
                                 <a class="mui-btn mui-btn-danger refund" style="height: 25px;line-height: 15px;" data-id="<?=$r->id?>" data-name='<?=$rooms[$r->room_id]['name']?>'><i class="iconfont" style="font-size: 16px;">&#xe6bf;</i></a>
                            </span>
                        </p>

                    <?php }?>

                    <?php $cust = yii\helpers\ArrayHelper::map($r->orderRoomCustomer, 'id', 'customer_id');
                    ?>
                    <p class="sp2">
                         <?php foreach($model->customer as $c){ ?>
                            <?php if(in_array($c->id,$cust)){ ?>
                                <?=sprintf("%s%s&nbsp;&nbsp;",$c->first_name,$c->last_name)?>
                            <?php }?>   
                         <?php }?>
                    </p>
                    </div>
                    <?php }?>   
            </div>
        </div>
        <div class="mui-card-footer">
            <a href="/member/member/order-detail?id=<?=$model->id?>" data-link="as" class="mui-btn line-btn">上传资料</a>
            <?php if(\Yii::$app->user->can('room_stock')){  ?>
            <a href="/front/default/line-room?id=<?=$model->product_id?>" data-link="as" class="mui-btn mui-pull-right line-btn">查看库存</a>
            <?php }?>   
        </div>
    </div>
	

</div>


<?= yii\web\View::registerJsFile("/js/localResizeIMG/lrz.all.bundle.js",['depends' => 'app\assets\MuiAsset']) ?>
<?= yii\web\View::registerJsFile("/js/layer_mobile/layer.js",['depends' => 'app\assets\MuiAsset']) ?>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">
 mui.init({});
 
 mui('body').on('tap','a[data-link="as"]',function(){document.location.href=this.href;return false});

mui("body").on('tap','.refund',function(){

    var id = jQuery(this).attr("data-id");
    var name = jQuery(this).attr("data-name");
   
    var html = '<textarea id="order-refund" class="form-control" placeholder="取消原因" maxlength="255" rows="4" style="padding:5px;"></textarea>'+
              '<input type="hidden" id="refund-room-id" value="'+id+'">';
    layer.open({
      title: [
        name+' 取消',
        'background-color:#a664a6; color:#fff;'
      ]
      ,anim: 'up'
      ,content: html
      ,btn: ['确认', '取消'],
      yes: function(){
            var id = jQuery("#refund-room-id").val();
            var desc = jQuery("#order-refund").val();
            $.get("/order/room/remove", {id: id, desc: desc}, function(data){
                    //console.log(data);
                    //alert(data);
                    if(data == 'true'){
                         window.location.reload();
                    }else if(data == 'error1'){

                        alert("请先取消舱房填写的入住人");
                    }else if(data == 'error2'){
                        alert("请先取消拼住的舱房");
                    }else{
                    
                    }
            });
      }

    });


});


</script>

<?php app\components\JsBlock::end() ?>
